/* Jeff Anderson (9/1/2006) */
/* http://www.codetoad.com/javascript_get_selected_text.asp */

function getSelText()
{
    var txt = "";
    if (window.getSelection) {
        txt = window.getSelection();
    }
    else if (document.getSelection) {
        txt = document.getSelection();
    }
    else if (document.selection) {
        txt = document.selection.createRange().text;
    }
    return txt;
}

function google_selection()
{
    var txt = getSelText();
    if (txt != "") {
	window.open("http://www.google.com/search?q="+txt);
    }
}

function translate_selection()
{
    var sbox = document.forms[0].sl;
    var sl = sbox.options[sbox.selectedIndex].value;
    var tbox = document.forms[0].tl;
    var tl = tbox.options[tbox.selectedIndex].value;
    var txt = getSelText();
    if (txt != "") {
	window.open("http://translate.google.com/translate_t?sl="+sl+"&tl="+tl+"&text="+txt);
     }	
}

function multi_line() 
{
    var msgspan = document.getElementById('msgspan');
    var txtspan = document.getElementById('txtspan');
    var ihtml = txtspan.innerHTML;
    if (ihtml.length) {
	var inp = document.getElementById('cmsg');
	var txt = inp.value;
	txtspan.innerHTML = "";
	msgspan.innerHTML = "<input id='cmsg' name='MSG' size='128' value='"+txt+"' />";
    }
    else {
	var inp = document.getElementById('cmsg');
	var txt = inp.value;
	msgspan.innerHTML = "";
	txtspan.innerHTML = "<textarea rows='8' cols='128' compact='0' name='MSG' id='cmsg'>"+txt+"</textarea>";
    }
}
